package com.controller;

import com.bean.User;
import com.services.UserServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

@RequestMapping("/Users")
@Controller
public class UserController {
    @Autowired
    @Qualifier("userServicesimpl")
    private UserServices userServices;

    @RequestMapping("/AllUsers")
    public String AllUsers(Model model){
        List<User> list =new ArrayList<>();
        list=userServices.selectAllUser();
        model.addAttribute("list",list);
        return "AllUsers";
    }
//跳转到添加页面
    @RequestMapping("/toAdd")
    public String toAdd(){
        return "addUser";
    }

    //用户添加成功跳查询全部页面
    @RequestMapping("/addUser")
    public String addUser(User user){
            System.out.println(user.getIduser()+user.getName()+"=======");
            userServices.addUser(user);
            return "redirect:/Users/AllUsers";
    }
}
